<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2017 河源市卓锐科技有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------
// | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------

	namespace app\cms\api;

	use think\Db;

	/**
	 * 前台搜索控制器
	 * @package app\cms\admin
	 */
	class Search extends Common
	{
		/**
		 * 搜索列表
		 * @param string $keyword 关键词
		 * @return mixed
		 * @throws \think\exception\DbException
		 */
		public function index($keyword = '')
		{
			if ($keyword == '')
				$this->error('请输入关键字');
			$map = [
				'cms_document.trash'  => 0,
				'cms_document.status' => 1,
				'cms_document.title'  => ['like', "%$keyword%"]
			];

			$data_list = Db::view('cms_document', true)
				->view('admin_user', 'username', 'cms_document.uid=admin_user.id', 'left')
				->where($map)
				->order('create_time desc')
				->paginate(config('list_rows'));

			$this->result([
				'keyword' => $keyword,
				'lists'   => $data_list,
				'pages'   => $data_list->render(),
			]);
		}
	}